package com.koron.system.role.controller;

import com.koron.bean.base.BaseQueryBean;
import com.koron.bean.base.Response;
import com.koron.bean.system.role.RoleBean;
import com.koron.bean.system.role.RoleJurisdictionBean;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.annocation.CasUser;
import com.koron.system.role.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @ClassName RoleController
 * @description
 * @Author zhouj
 * @Date 2021/7/22 14:06
 */
@RestController
@RequestMapping("/system/role")
@Api(tags = "角色管理")
public class RoleController {

    @Autowired
    RoleService roleService;

    @ApiOperation(value = "新增角色")
    @PostMapping("/insertRole")
    public Response insertRole(@RequestBody RoleBean roleBean, @ApiIgnore @CasUser EamUser user) {
        return Response.success(roleService.insertRole(user, roleBean));
    }

    @ApiOperation(value = "修改角色")
    @PutMapping("/updateRole")
    public Response updateRole(@RequestBody RoleBean roleBean, @ApiIgnore @CasUser EamUser user) {
        return Response.success(roleService.updateRole(user, roleBean));
    }

    @ApiOperation(value = "删除角色")
    @DeleteMapping("/delete")
    public Response deleteRoleById(String id) {
        return Response.success(roleService.deleteRoleById(id));
    }

    @ApiOperation(value = "删除角色list")
    @DeleteMapping("/deleteList")
    public Response deleteRoleList(@RequestParam("ids") List<String> ids) {
        return Response.success(roleService.deleteRoleList(ids));
    }

    @ApiOperation(value = "根据组织查询角色列表")
    @GetMapping("/queryOrgList")
    public Response queryRoleList(RoleBean roleBean, BaseQueryBean queryBean) {
        return Response.success(roleService.queryRoleList(roleBean, queryBean), roleService.queryRoleListCount(roleBean));
    }

    @ApiOperation(value = "查询单个角色信息")
    @GetMapping("/querySingleRole")
    public Response querySingleRole(RoleBean roleBean) {
        return Response.success(roleService.querySingleRole(roleBean));
    }

    @ApiOperation(value = "保存角色权限")
    @PostMapping("/saveRoleJurisdiction")
    public Response saveRoleJurisdiction(@RequestBody RoleJurisdictionBean roleJurisdictionBean, @ApiIgnore @CasUser EamUser user) {
        return Response.success("保存成功", roleService.saveRoleJurisdiction(user, roleJurisdictionBean));
    }

    @ApiOperation(value = "根据roleId单独查询水司权限")
    @GetMapping("/queryAppJurisdiction")
    public Response queryAppJurisdiction(@RequestParam(value = "roleId") String roleId, @ApiIgnore @CasUser EamUser user) {
        return Response.success(roleService.queryAppJurisdiction(roleId));
    }

    @ApiOperation(value = "根据roleId单独查询组织权限")
    @GetMapping("/queryOrgJurisdiction")
    public Response queryOrgJurisdiction(@RequestParam(value = "roleId") String roleId, @RequestParam(value = "appId", required = false) String appId, @ApiIgnore @CasUser EamUser user) {
        return Response.success(roleService.queryOrgJurisdiction(roleId, appId));
    }

    @ApiOperation(value = "根据roleId单独查询菜单权限")
    @GetMapping("/queryMenuJurisdiction")
    public Response queryMenuJurisdiction(@RequestParam(value = "roleId") String roleId, @RequestParam(value = "appId", required = false) String appId, @ApiIgnore @CasUser EamUser user) {
        return Response.success(roleService.queryMenuJurisdiction(roleId, appId));
    }

    @ApiOperation(value = "根据roleId单独查询角色配置的人员及组织")
    @GetMapping("/queryUserJurisdiction")
    public Response queryUserJurisdiction(@RequestParam(value = "roleId", required = false) String roleId, @ApiIgnore @CasUser EamUser user) {
        return Response.success(roleService.queryUserJurisdiction(roleId));
    }

    @ApiOperation(value = "根据roleId单独查询全部水司,组织,菜单权限")
    @GetMapping("/queryAppAllInfoJurisdiction")
    public Response queryAppAllInfoJurisdiction(@RequestParam(value = "roleId") String roleId, @RequestParam(value = "appId", required = false) String appId) {
        return Response.success(roleService.queryAppAllInfoJurisdiction(roleId, appId));
    }

    @ApiOperation(value = "查询用户拥有的角色或者用户所属组织拥有的角色")
    @GetMapping("/queryUserRole")
    public Response queryUserRole(@RequestParam(value = "account", required = false) String account) {
        return Response.success(roleService.queryUserRole(account));
    }

    @ApiOperation(value = "查询用户拥有的水司权限列表")
    @GetMapping("/queryAppJurisdictionByAccount")
    public Response queryAppJurisdictionByAccount(@RequestParam(value = "account") String account) {
        return Response.success(roleService.queryAppJurisdictionByAccount(account));
    }

    @ApiOperation(value = "保存用户拥有角色")
    @PutMapping("/saveUserRole")
    public Response saveUserRole(@RequestParam(value = "account") String account, @RequestBody List<String> roleIds) {
        return Response.success(roleService.saveUserRole(account, roleIds));
    }

    @ApiOperation(value = "删除用户拥有角色")
    @DeleteMapping("/deleteUserRole")
    public Response deleteUserRole(@RequestParam(value = "account") String account, @RequestParam(value = "roleId") String roleId) {
        return Response.success(roleService.deleteUserRole(account, roleId));
    }

    @ApiOperation(value = "查询用户拥有的权限")
    @GetMapping("/queryUserOwnRoleJurisdiction")
    public Response queryUserOwnRoleJurisdiction(@RequestParam(value = "account") String account) {
        return Response.success(roleService.queryUserOwnRoleJurisdiction(account));
    }

    @ApiOperation(value = "查询用户拥有的权限ALL")
    @GetMapping("/queryUserOwnRoleJurisdictionAll")
    public Response queryUserOwnRoleJurisdictionAll(@RequestParam(value = "account") String account) {
        return Response.success(roleService.queryUserOwnRoleJurisdictionAll(account));
    }

}
